<template>
    <div class="theTest-less">
        <el-form :inline="true" :model="formInline" class="demo-form-inline t-a-l">
            <el-form-item label="名称：">
                <el-input v-model="keyWord" placeholder=""></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit">搜索</el-button>
                <el-button class="reset" @click="reset()">重置</el-button>
            </el-form-item>
        </el-form>
        <div class="export-less">
            <el-button type="primary" @click="centerDialogVisible = true,isDisabled = false,rejected = {},title='新增信息'">新增</el-button>
        </div>
        <div class="border-s my-test">
            <el-table :data="tableData" style="width: 100%" :border="false">
                <el-table-column prop="name" label="考试名称"></el-table-column>
                <el-table-column prop="address" label="考试地点"></el-table-column>
                <el-table-column prop="examTime" label="考试时间"></el-table-column>
                <el-table-column prop="applyStartTime" label="报名开始时间"></el-table-column>
                <el-table-column prop="applyEndTime" label="报名结束时间"></el-table-column>
                <el-table-column prop="payEndTime" label="付费截止时间"></el-table-column>
                <el-table-column prop="delayedEndTime" label="缓考截止时间"></el-table-column>
                <el-table-column prop="description" label="考试说明"></el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button @click="centerDialogVisible = true,isDisabled = true,selectExamination(scope.row.id),title='查看信息'" type="text" size="medium" class="button-my-test">查看</el-button>
                        <el-button @click="centerDialogVisible = true,isDisabled = false,selectExamination(scope.row.id),title = '修改信息'" type="text" size="medium" class="button-my-test">修改</el-button>
                        <el-button @click="confirm(scope.row.id)" type="text" size="medium" class="button-my-test">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <el-pagination
            background
            layout="total, sizes, prev, pager, next, jumper"
            :page-size="formInline.pageable.size"
            @current-change="handleCurrentChange"
            :page-sizes="[10, 20, 30, 40]"
            @size-change="pageFy"
            :total="total">
            </el-pagination>
        <el-dialog :title="title" class="rejected" :visible.sync="centerDialogVisible" width="30%" center>
            <el-form ref="form" :model="rejected" label-width="120px">
                <el-form-item label="考试名称:">
                    <el-input type="text" v-model="rejected.name" :disabled="isDisabled"></el-input>
                </el-form-item>
                <el-form-item label="考试地点:">
                    <el-input type="text" v-model="rejected.address" :disabled="isDisabled"></el-input>
                </el-form-item>
                <el-form-item label="考试时间:">
                    <el-date-picker v-model=" rejected.examTime" type="datetime" placeholder="选择日期时间" value-format="yyyy-MM-dd HH:mm:ss" :disabled="isDisabled" :clearable="true"> </el-date-picker>
                    <span>{{examTime}}</span>
                </el-form-item>
                <el-form-item label="报名开始时间:">
                    <el-date-picker v-model="rejected.applyStartTime" type="datetime" placeholder="选择日期时间" value-format="yyyy-MM-dd HH:mm:ss" :disabled="isDisabled" :clearable="true"> </el-date-picker>
                </el-form-item>
                <el-form-item label="报名结束时间:">
                    <el-date-picker v-model="rejected.applyEndTime" type="datetime" placeholder="选择日期时间" value-format="yyyy-MM-dd HH:mm:ss" :disabled="isDisabled" :clearable="true"> </el-date-picker>
                </el-form-item>
                <el-form-item label="付费截止时间:">
                    <el-date-picker v-model="rejected.payEndTime" type="datetime" placeholder="选择日期时间" value-format="yyyy-MM-dd HH:mm:ss" :disabled="isDisabled" :clearable="true"> </el-date-picker>
                </el-form-item>
                <el-form-item label="缓考截止时间:">
                    <el-date-picker v-model="rejected.delayedEndTime" type="datetime" placeholder="选择日期时间" value-format="yyyy-MM-dd HH:mm:ss" :disabled="isDisabled" :clearable="true"> </el-date-picker>
                </el-form-item>
                <el-form-item label="考试说明:">
                    <el-input type="text" v-model="rejected.description" :disabled="isDisabled"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button size="medium" @click="centerDialogVisible = false">取 消</el-button>
                <el-button size="medium" type="primary" @click="centerDialogVisible = false,addExamination()">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>
<script>
import apiHttp from '../../api/index.js'
export default {
    data(){
        return{
            formInline: {
                conditions:[],
                pageable:{
                    current:1,
                    size:10
                },
            },
            tableData:[],
            centerDialogVisible:false,
            toView:false,
            rejected:{},
            total:0,
            isDisabled:false,
            title:'',
            keyWord:'',
            examTime:'',
        }
    },
    watch:{
        rejected:{
            deep: true,
            handler(newVal,oldVal){
                apiHttp.apiIndex.infoDateSeason(newVal.examTime).then(resp =>{
                    if(resp.code == 0){
                        this.examTime = resp.data
                    }
                })
            }
        }
    },
    mounted(){
        this.examinatiList()
    },
    methods:{
        // 重置搜索内容
        reset(){
            this.keyWord = ''
            this.examinatiList()
        },
        // 获取列表
        examinatiList(){
            apiHttp.apiIndex.examinationPage(this.formInline).then(resp=>{
                if(resp.code == 0){
                    this.tableData = resp.data.records
                    this.total = Number(resp.data.total)
                    this.formInline.conditions = []
                }
            })
        },
        // 添加
        addExamination(){
            apiHttp.apiIndex.examinationData(this.rejected).then(resp=>{
                if(resp.code == 0){
                    this.examinatiList()
                    this.rejected = {}
                }
            })
        },
        // 分页（翻页）
        handleCurrentChange(val){
            this.formInline.pageable.current = val
            this.examinatiList()
        },
        pageFy(val){
            this.formInline.pageable.size = val
            this.examineeList()
        },
        // 获取单条信息详情
        selectExamination(id){
            apiHttp.apiIndex.selectExaminationData(id).then(resp=>{
                if(resp.code == 0){
                    this.rejected = resp.data
                }
            })
        },
        // 搜索
        onSubmit(){
            if(this.keyWord){
                let obj = {
                    expression:'contain',
                    column:'name',
                    value:this.keyWord
                }
                this.formInline.conditions.push(obj)
                this.examinatiList()
            }else{
                this.formInline.conditions = []
                this.examinatiList()
            }
        },
        // 删除
        confirm(id) {
            this.$confirm('您确定要删除吗?', '', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                center:'true'
            }).then(() => {
                apiHttp.apiIndex.examinationDelete(id).then(resp=>{
                    if(resp.code == 0){
                        this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                        this.examinatiList()
                    }
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消'
                });          
            });
      }
    }
}
</script>
<style lang="less">
.theTest-less{
    .el-form{
        .el-form-item{
            .el-form-item__content{
                .el-button--primary{
                    background-color: #5d2805;
                    border-color: #5d2805;
                }
            }
        }
    }
    .export-less{
        text-align: left;
        margin-bottom: 15px;
        .jiafei{
            display: block;
            margin-top: 15px;
        }
    }
    .el-table th{
        color: #fff;
        background-color: #5d2805;
    }
    .el-table td, .el-table th{
        text-align: center;
        font-size: 16px;
    }
    .rejected{
        .el-dialog__body{
            padding: 25px 25px 10px;
            // .el-form-item__label{
            //     display: none;
            // }
            // .el-form-item__content{
            //     margin-left: 0 !important;
            // }
        }
        .el-dialog__footer{
            .el-button--primary{
                background-color: #5d2805;
                border-color: #5d2805;
            }
            .el-button--default:hover{
                background-color: #e4d7cf;
                border-color: #e4d7cf;
                color: #5d2805;
            }
        }
        .el-textarea__inner{
            min-height: 100px !important;
        }
    }
}
.el-message-box__message{
    font-size: 18px;
}
</style>

